package com.leo.chapter06;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 串行处理，性能低，浪费服务器资源
 * @author xuexiaolei
 * @version 2017年10月15日
 */
public class SingleThreadWebServer {
    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(80);
        while (true){
            Socket connection = socket.accept();
            handleRequest(connection);
        }
    }

    public static void handleRequest(Socket connection){
        try {
            System.out.println("正在处理");
            Thread.sleep(1000);
            System.out.println("处理完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
